
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="javax.portlet.PortletPreferences"%>
<%@page import="org.w3c.dom.NodeList"%>
<%@page import="org.w3c.dom.Element"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.net.URL"%>
<%@page import="org.w3c.dom.Document"%>
<%@page import="java.io.File"%>
<%@page import="javax.xml.parsers.DocumentBuilder"%>
<%@page import="javax.xml.parsers.DocumentBuilderFactory"%>
<%
	/**
	 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
	 *
	 * This library is free software; you can redistribute it and/or modify it under
	 * the terms of the GNU Lesser General Public License as published by the Free
	 * Software Foundation; either version 2.1 of the License, or (at your option)
	 * any later version.
	 *
	 * This library is distributed in the hope that it will be useful, but WITHOUT
	 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
	 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
	 * details.
	 */
%>

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>

<portlet:defineObjects />
<script type="text/javascript">
	// when the DOM is ready, convert the feed anchors into feed content 
	jQuery(document).ready(function() {

		jQuery(function() {
			jQuery('#newsslider').accessNews({
				headline : "Eventos",
				speed : "slow",
				slideBy : 4
			});
		});
	});
</script>


<%
	PortletPreferences prefs = renderRequest.getPreferences();

	SimpleDateFormat formatoDB = new SimpleDateFormat("yyyy-MM-dd");
	SimpleDateFormat formatoView = new SimpleDateFormat("dd/MM");

	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	dbf.setNamespaceAware(false);

	DocumentBuilder docBuilder = dbf.newDocumentBuilder();
	URL eventosURL = new URL("http://10.52.152.2/eventos/eventos.xml");
	InputStream isEventos = eventosURL.openStream();

	Document docEventos = docBuilder.parse(isEventos);

	Element eventosTag = docEventos.getDocumentElement();
	NodeList eventosTags = eventosTag.getElementsByTagName("evento");
%>
<h1 style="border-bottom: 2px dotted #ccc;">Eventos</h1>

<div id="news_main_container">


	<ul id="list">

		<%
			for (int i = 0; i < eventosTags.getLength(); i++) {
				Element eventoTag = (Element) eventosTags.item(i);
				URL fotosURL = new URL(
						"http://10.52.152.2/eventos/fotos.xml?evento_id="
								+ eventosTag.getElementsByTagName("id").item(i)
										.getTextContent());
				InputStream isFotos = fotosURL.openStream();
				Document docFotos = docBuilder.parse(isFotos);
				Element fotosTag = docFotos.getDocumentElement();
				NodeList fotosTags = fotosTag.getElementsByTagName("foto");
				Element fotoTag = (Element) fotosTags.item(0);

				session.setAttribute("eventoId", eventoTag
						.getElementsByTagName("id").item(0).getTextContent());
		%>
		<portlet:renderURL var="detailEventoURL">
			<portlet:param name="jspPage" value="/detail.jsp" />
			<portlet:param name="eventoId" value="${eventoId}" />
		</portlet:renderURL>

		<li><a href="<%=detailEventoURL%>"><img
				src="/image-proxy/eventos/experience?id=<%=fotoTag.getElementsByTagName("id").item(0)
						.getTextContent()%>"
				width="82" height="30" /> </a>
			<p>
				<a class="title" href="<%=detailEventoURL%>"> <%=eventoTag.getElementsByTagName("titulo").item(0)
						.getTextContent()%>
				</a>
			</p>
			<p class="description">
				<%=eventoTag.getElementsByTagName("texto_resumo")
						.item(0).getTextContent()%>
				<a href="<%=detailEventoURL%>"> &raquo; Leia mais</a>
			</p></li>




		<%
			}
		%>

	</ul>
</div>
